﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcRags.Examples.Models;
using MvcRags.Filtering;
using MvcRags.Pagination;
using MvcRags.Sorting;

namespace MvcRags.Examples.Controllers
{
    public class MixedController : Controller
    {
        ExampleDataContext db = new ExampleDataContext();
        //
        // GET: /Mixed/

        public ActionResult Index()
        {
            FilterMode filterMode = FilterMode.Contains;

            string filterModeString = Request.Params["filterMode"];
            if (!string.IsNullOrWhiteSpace(filterModeString))
                filterMode = (FilterMode)Int32.Parse(filterModeString);
            ViewBag.SelectedFilterMode = ((int)filterMode).ToString();

            IQueryable<Customer> filteredCustomers = this.Filter(db.Customers, filterMode);
            IOrderedQueryable<Customer> sortedCustomers = this.Sort(filteredCustomers, m => m.Name);
            IQueryable<Customer> customers = this.Paginate(sortedCustomers);
            return View(customers);
        }

    }
}
